<template>
  <div>
    <div class="publicTop">
      <div class="publicCenter">
<a href="/front/myVue%20-%20副本/static" class="publicLogo" title="">
<!-- <img class="img" src="http://cq12df.oss-cn-hangzhou.aliyuncs.com/tu1/new.jpg" alt=""> -->
</a>
<div class="publicLogoY">创乐园</div>
<ul class="publicNav">
				<li class="publicNavTxt"><a class="a1" href="/register/" title="用户注册" >用户注册</a></li>

        <li  class="publicNavTxt"><a class="a1" href="/front/myVue%20-%20副本/static" title="首页" >首页</a></li>
			</ul>
      </div>
    </div>
<div class="clear"></div>
<div id="content" class="content">
<div class="login-wrap">
<div class="login-banner">
<div id="banner-bg" class="banner-bg">
<div class="login-inner">
<div class="login-form">
<div class="login-block">
<div class="login-title l-r-title">
									<div class="l-r-txt">
										<span class="cur" @click="denglu()" id=dl>登录</span>
										<em class="sep-long"></em>
										<span><a class="areg" @click="register()" id="ze">注册</a></span>
									</div>
									<div class="login-way">
										<div class="switch-box qrLoginY" title="二维码登录">
											<div class="switch-bg icon-sprite"></div>
										</div>
									</div>
								</div>
<div class="login-box">
<div class="form">
  <form type="formlogin" class="form" method="post" id="form2" name="form2" action="/Login/doLogin/activity_login_type/0.html">

<div id="denglu" style="diaplay:block">
                      <div style="display: block;" id="youxiang1">
                        <div class="account-login" >
												<a class="ak" @click="mima">账号密码登录</a>
											</div>
<div class="item m-container input-item item-fore1" >
												<label for="loginname" class="icon-sprite reg-phone-icon"></label>
												<input class="input" type="text"  autocomplete="off" v-model="mail" placeholder="请输入邮箱"  >
                        	<span class="clear-btn" style="display:inline;">×</span>
											</div>



<div class="item m-container input-item item-fore8"  >
												<label for="phoneverification" class="icon-sprite reg-note-verify-icon"></label>
												<input class="input2" type="text"  autocomplete="off" v-model="code" placeholder="请输入邮箱验证码" >
											 <el-button :disabled="disabled" class="get-verify" @click="sendcode()">{{btntxt}}</el-button>
											</div>

             <div class="item m-container item-fore5">
												<div class="login-btn">
													<a @click="login1"  class="btn-img btn-entry"  >立即登录</a>
												</div>
											</div>
                      </div>

                      <div style="display:none" id="youxiang2">
                         <div class="phone-login" >
												<a class="ak" @click="youxiang">邮箱快捷登录</a>
											</div >
<div class="item m-container input-item item-fore1" >
												<label for="loginname2" class="icon-sprite reg-phone-icon"></label>
											<input type="text"  autocomplete="off" v-model="username" class="input"   placeholder="用户名/邮箱" >
											 	<span class="clear-btn" style="display:inline;">×</span>
											</div>


<div class="item m-container input-item item-fore1" >
												<label for="loginname" class="icon-sprite reg-phone-icon"></label>
												<input class="input2" type="text"  autocomplete="off" v-model="password" placeholder="请输入密码"  >
											</div>

                       <div class="item m-container item-fore5">
												<div class="login-btn">
                        <a @click="login2"  class="btn-img btn-entry"  >立即登录</a>

												</div>
											</div>

</div>
</div>
 <div id="zhuce" style="display:none">
<div class="item m-container input-item item-fore1" >
												<label for="loginname" class="icon-sprite reg-phone-icon"></label>
												<input class="input" type="text" :rules="rules"  autocomplete="off" v-model="mail" placeholder="请输入邮箱"  >
                        	<span class="clear-btn" style="display:inline;">×</span>
											</div>

  <div class="item m-container input-item item-fore8"  >
												<label for="phoneverification" class="icon-sprite reg-note-verify-icon"></label>
												<input class="input2" type="text"  autocomplete="off" v-model="code" placeholder="请输入邮箱验证码" >
											 <el-button :disabled="disabled1" class="get-verify" @click="sendcode1()">{{btntxt1}}</el-button>
											</div>
                       <div class="item m-container input-item item-fore1" >
												<label  class="icon-sprite reg-phone-icon"></label>
												<input class="input2" type="text"  autocomplete="off" v-model="username" placeholder="请输入用户名"  >
											</div>
  <div class="item m-container input-item item-fore1" >
												<label  class="icon-sprite reg-phone-icon"></label>
												<input class="input2" type="text"  autocomplete="off" v-model="password" placeholder="请输入密码,不少于6位"  >
											</div>
  <div class="item m-container item-fore5">
												<div class="login-btn">
													<a @click="zhuce()"  class="btn-img btn-entry" >立即注册</a>
												</div>
											</div>
 </div>

  </form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
  </div>
</template>
<script>
import axios from 'axios'
export default {

  data() {
    return {
      mail:'',  //邮箱
      code:'',  //验证码
      username:'', //用户名
      password:'',  //密码

      disabled:false,
				time:60,
				btntxt:"发送验证码",

      disabled1:false,
				time1:60,
				btntxt1:"发送验证码",
        rules: {
                    mail: [{ required: true, message: '请填写电子邮箱', trigger: 'change' }]
                }
    }
  },
  methods: {
    zhuce(){
       let regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
      let url='http://localhost:8098/register';
      let params={
        mail:this.mail,
        username:this.username,
        password:this.password
      }
      if(this.username.trim()==''){
        this.$message({
            showClose: true,
          message: '用户名不能为空',
          type: 'error'
        });
      }else if(this.password.trim().length<6){
          this.$message({
            showClose: true,
          message: '密码格式不正确',
          type: 'error'
        });
      }
      else if(localStorage.getItem(this.mail)!==this.code){
        this.$message({
            showClose: true,
          message: '验证码错误',
          type: 'error'
        });
      }else
      {axios.post(url,params).then(resp=>{
        let result=resp.data;
        if(result.code===200){
          localStorage.removeItem(this.mail);
           this.mail=undefined;
      this.code=undefined;
      this.username=undefined;
      this.password=undefined;
          this.$message({
            showClose: true,
          message: '注册成功，请登录',
          type: 'success'
        });
        }
      })
      }

    },
    denglu(){
       this.mail=undefined;
      this.code=undefined;
      this.username=undefined;
      this.password=undefined;
document.getElementById("ze").style.color="#888";
      document.getElementById("dl").style.color="#222";
       document.getElementById("zhuce").style.display="none";
      document.getElementById("denglu").style.display="block"
    },
    register(){
      this.mail=undefined;
      this.code=undefined;
      this.username=undefined;
      this.password=undefined;
      document.getElementById("ze").style.color="#222";
      document.getElementById("dl").style.color="#888"
      document.getElementById("zhuce").style.display="block";
      document.getElementById("denglu").style.display="none"
    },
    login1(){
      if(localStorage.getItem(this.mail+"login")!==this.code){
         this.$message({
            showClose: true,
          message: '验证码错误',
          type: 'error'
        });

      }else{
        let url='http://localhost:8098/loginMail';
        let param=`mail=${this.mail}`
        axios.post(url,param).then(resp=>{
          let result=resp.data;
          if(result.code===200){
            localStorage.setItem("token",result.host)
            localStorage.setItem("user",JSON.stringify(result.data))

        this.$router.push('/')
        this.$message({
            showClose: true,
          message: '登录成功',
          type: 'success'
        });
          }else{
            this.$message({
            showClose: true,
          message: result.errorMessage,
          type: 'error'
        });
          }
        })
      }
    },
    login2(){
      if(this.username.trim()==''||this.password==''){
        this.$message({
            showClose: true,
          message: '用户名或密码不能为空',
          type: 'error'
        });
      }else{
         let url='http://localhost:8098/login';
         let param={
          username:this.username,
          password:this.password
         }
      axios.post(url,param).then(resp=>{
        let result=resp.data;
        if(result.code===200){
            localStorage.setItem("token",result.host)
            this.$message({
            showClose: true,
          message: '登录成功',
          type: 'success'
        });
        this.$router.push('/')
          }else{
            this.$message({
            showClose: true,
          message: result.errorMessage,
          type: 'error'
        });
          }
      })
      }

    },
    youxiang(){
      this.mail=undefined;
      this.code=undefined;
      document.getElementById("youxiang1").style.display="block"
      document.getElementById("youxiang2").style.display="none"
    },
    mima(){
      this.username=undefined;
      this.password=undefined;
      document.getElementById("youxiang1").style.display="none"
      document.getElementById("youxiang2").style.display="block"
    },
    // 注册发送邮箱
  sendcode1(){
     let regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        let url='http://localhost:8098/sendMail@1/send'
        let param=`mail=${this.mail}`
        if(this.mail.trim()==''||this.mail==null){
          this.$message({
            showClose: true,
          message: '邮箱不能为空',
          type: 'error'
        });
        this.mail=undefined;
        }else if(!regEmail.test(this.mail)){
          this.$message({
            showClose: true,
          message: '邮箱格式不正确',
          type: 'error'
        });
        }else {
          axios.post(url,param).then(resp=>{
            let result=resp.data
            if(result.code===200){
              localStorage.setItem(this.mail,result.data)
              this.$message({
            showClose: true,
          message: '邮箱发送成功，请注意接收',
          type: 'success'
        });
            }
            else if(result.code===300){
               this.$message({
            showClose: true,
          message: result.errorMessage,
          type: 'error'
        });
              }else{
              this.$message({
            showClose: true,
          message: '发送失败',
          type: 'error'
        });
            }
          });
        this.time1=60;
				this.timer1();
        }
  },
  // 登录发送邮箱
			sendcode(){
        let regEmail = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        let url='http://localhost:8098/sendMail@1/sendlogin'
        let param=`mail=${this.mail}`
        if(this.mail.trim()==''||this.mail==null){
          this.$message({
            showClose: true,
          message: '邮箱不能为空',
          type: 'error'
        });
        this.mail=undefined;
        }else if(!regEmail.test(this.mail)){
          this.$message({
            showClose: true,
          message: '邮箱格式不正确',
          type: 'error'
        });
        }else {
          axios.post(url,param).then(resp=>{
            let result=resp.data
            if(result.code===200){
              localStorage.setItem(this.mail+"login",result.data)
              this.$message({
            showClose: true,
          message: '邮箱发送成功，请注意接收',
          type: 'success'
        });
            }else{
              this.$message({
            showClose: true,
          message: '发送失败',
          type: 'error'
        });
            }
          });
          this.time=60;
				this.timer();
        }



			},
			//发送手机验证码倒计时
			timer() {
				if (this.time > 0) {
					this.disabled=true;
					this.time--;
					this.btntxt=this.time+"秒";
					setTimeout(this.timer, 1000);
				} else{
					this.time=0;
					this.btntxt="发送验证码";
					this.disabled=false;
				}

			},
      	timer1() {
				if (this.time1 > 0) {
					this.disabled1=true;
					this.time1--;
					this.btntxt1=this.time1+"秒";
					setTimeout(this.timer1, 1000);
				} else{
					this.time1=0;
					this.btntxt1="发送验证码";
					this.disabled1=false;
				}

			},
		}
}

</script>
<style  scoped>
.btn-img {
    display: block;
    width: 340px;
    background: #fc3737;
    height: 44px;
    line-height: 44px;
    color: #fff;
    font-size: 18px;
    font-family: Microsoft YaHei;
    border-radius: 4px;
    transition: all .3s;
    text-decoration: none;
    cursor: pointer;
}
.item-fore5 {
    height: 44px;
    position: relative;
    text-align: center;
    margin: 38px auto 0;
}
.get-verify {
    right: 5px;
    z-index: 9;
        outline: none;
    cursor: pointer;
    padding: 0;
        top: 8px!important;
            position: absolute!important;
    left: auto!important;
    width: 74px;
    height: 25px;
    border: 0;
    color: #fff;
    background: #fc3737;
    border-radius: 2px;
    text-align: center;
    line-height: 25px;
    font-size: 12px;
}
.input2{
  border: 0;
    outline: none;
    height: 42px;
    padding: 0 40px;
      width: 206px;
    padding-right: 82px;
}
.icon-sprite:after {
    content: "";
    position: absolute;
    vertical-align: middle;
    background-image: url(//zuhaowan.zuhaowan.com/static/www3.0/dubhe/pages/login/img/login-sprite.0aa7103.png);
    background-repeat: no-repeat;
}
.reg-note-verify-icon.icon-sprite:after {
    top: 17px;
    left: 14px;
    width: 14px;
    height: 12px;
    text-align: center;
    background-position: -187px -17px;
    transition: all .3s;
}
.clear-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 15px;
    height: 15px;
    line-height: 13px;
    text-align: center;
    border-radius: 50%;
    color: #fff;
    background: #787878;
    cursor: pointer;
    font-size: 13px;
}
.icon-sprite:after {
    content: "";
    position: absolute;
    vertical-align: middle;
    background-image: url(//zuhaowan.zuhaowan.com/static/www3.0/dubhe/pages/login/img/login-sprite.0aa7103.png);
    background-repeat: no-repeat;
}
.reg-phone-icon.icon-sprite:after {
    top: 14px;
    left: 14px;
    width: 11px;
    height: 15px;
    text-align: center;
    background-position: -100px -13px;
    transition: all .3s;
}
.input{
      border: 0;
    outline: none;
    width: 258px;
    height: 42px;
    padding: 0 40px;
}

.icon-sprite{
  position: absolute;
    top: 0;
    left: 0;
    width: 40px;
    height: 42px;
}
.input-item {
    width: 338px;
    height: 42px;
    border: 1px solid #e8e8e8;
    margin-bottom: 16px;
    position: relative;
}
.account-login {

    text-align: right;
    margin-top: -5px;
    margin-bottom: 12px;
}
.ak{
  text-decoration: none;
    cursor: pointer;
      color: #2563f4;
    font-size: 12px;
}
.phone-login {
    text-align: right;
    margin-top: -5px;
    margin-bottom: 12px;
}
.form{
  margin: 0;
    padding: 0;
}
.login-box {
    margin-top: 15px;
}
.areg{
      display: inline-block;
    color: #888;
    font-size: 18px;
    cursor: pointer;
    transition: color .3s;
}
.sep-long {
    display: inline-block;
    height: 15px;
    border-left: 1px solid silver;
    margin: 0 28px;
}
.cur{
      display: inline-block;
    font-size: 18px;
    cursor: pointer;
    transition: color .3s;
      color: #222;
}
 .l-r-txt {
    line-height: 1;
    float: left;
}
.l-r-title {
    height: 24px;
}
.login-block{
    padding: 32px 40px;
    height: auto;
}
 .login-form {
    width: 420px;
    height: auto;
    float: right;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 6px 68px 0 rgb(0 0 0 / 10%);
    position: relative;
}
.login-inner {
    width: 1200px;
    margin: 0 auto;
    padding-top: 170px;
    height: 673px;
}
.banner-bg {
      margin: 0;
    padding: 0;
    width: 100%;
    height: 842px;
    background: url(https://cq12df.oss-cn-hangzhou.aliyuncs.com/web/auth_bg.7c4e492.jpg) top no-repeat;
    margin-top: -70px;
}
.login-banner {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 772px;
}
.login-wrap {
    position: relative;
    height: 772px;
    z-index: 5;
}
.content {
    clear: both;
    color: #666;
    margin-top: -20px;
}
.clear {
    clear: both;
}
.a1 {
  text-decoration: none;
    display: inline-block;
    height: 30px;
    line-height: 30px;
    padding: 0 15px;
    color: #666;
    font-size: 14px;
}
.publicNavTxt {
    display: inline-block;
    float: right;
    height: 30px;
}
.publicNav {
    width: 50%;
    float: right;
    margin-top: 20px;
    height: 30px;
}
.publicLogoY {
    width: 280px;
    padding: 0 5px;
    margin-top: 20px;
    float: left;
    height: 30px;
    line-height: 30px;
    text-align: left;
    font-size: 14px;
    color: #666;
}
.publicLogo {
  text-decoration: none;
    cursor: pointer;
    width: 130px;
    display: inline-block;
    float: left;
}
.img {
    width: 100%;
        vertical-align: top;
}
.publicCenter {
  font-family: microsoft yahei;
    width: 1180px;
    height: 50px;
    margin: 0 auto;
    padding: 15px 10px;
    background: #fff;
}
.publicTop {
    margin-top: -10px;
    margin-right: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
    padding: 0;
    position: relative;
    z-index: 9;
    height: 86px!important;
        width: 100%;
    background: #fff;
}
</style>
